package com.bxl.netty.rpc.client.common.client;


import com.bxl.netty.rpc.client.common.rule.LoadBalance;

import java.util.ArrayList;
import java.util.List;

/**
 * <>
 *
 * @author baixl
 * @date 2021/2/24
 */
public class AppInfo {
    private String app;
    private List<ClientInfo> clients= new ArrayList<ClientInfo>();
    private List<ClientInfo> oldClients = new ArrayList<ClientInfo>();
    private LoadBalance loadBalance;
    public LoadBalance getLoadBalance() {
        return loadBalance;
    }

    public AppInfo() {
    }

    public AppInfo(String app) {
        this.app = app;
    }

    public void setLoadBalance(LoadBalance loadBalance) {
        this.loadBalance = loadBalance;
    }

    public String getApp() {
        return app;
    }

    public void setApp(String app) {
        this.app = app;
    }

    public List<ClientInfo> getClients() {
        return clients;
    }
    
    public void addClients(ClientInfo clientInfo){
        clients.add(clientInfo);
    }

    public void setClients(List<ClientInfo> clients) {
        this.clients = clients;
    }

    public ClientInfo getClient() {
        if (loadBalance == null) {
            return null;
        }
        return loadBalance.choose(clients);
    }

    public List<ClientInfo> getOldClients() {
        return oldClients;
    }

    public void setOldClients(List<ClientInfo> oldClients) {
        this.oldClients = oldClients;
    }
}
